package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.LevelPrivilegeDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegeCommand;
import com.cskaoyan.wordmemorize.request.LevelPrivilegePageRequest;
import com.cskaoyan.wordmemorize.service.LevelPrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/privilege")
public class AdminPrivilegeController {

    @Autowired
    LevelPrivilegeService levelPrivilegeService;
    
    @PostMapping("")
    public Result addPrivilege(@RequestBody LevelPrivilegeCommand levelPrivilegeCommand) {
        
        levelPrivilegeService.addLevelPrivilege(levelPrivilegeCommand);
        
        return Result.ok();
    }
    
    @PutMapping("")
    public Result updatePrivilege(@RequestBody LevelPrivilegeCommand levelPrivilegeCommand) {
        
        levelPrivilegeService.updateLevelPrivilege(levelPrivilegeCommand);
        
        return Result.ok();
    }
    
    @GetMapping("list")
    public Result<PageDTO<LevelPrivilegeDTO>> listPrivilege(LevelPrivilegePageRequest levelPrivilegePageRequest) {

        PageDTO<LevelPrivilegeDTO> levelPrivilegeList = levelPrivilegeService.getLevelPrivilegeList(levelPrivilegePageRequest);

        return Result.ok(levelPrivilegeList);
    }
    
    @DeleteMapping("{id}")
    public Result deletePrivilege(@PathVariable("id") Long id) {
        
        levelPrivilegeService.deleteLevelPrivilege(id);
        
        return Result.ok();
    }
    
    @DeleteMapping("batch")
    public Result deleteBatchPrivilege(@RequestBody BatchDeleteCommand batchDeleteCommand) {
        
        levelPrivilegeService.batchDeleteLevelPrivilege(batchDeleteCommand);
        
        return Result.ok();
    }
}
